<!DOCTYPE html>
<!--suppress ALL-->
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('评分')" />
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <h3 th:if="${type == 1}" class="form-header text-center">师德师风评分(学生)</h3>
    <h3 th:if="${type == 2}" class="form-header text-center">效绩考核评分(管理员)</h3>
    <form class="form-horizontal m" id="form-topic-score">
        <input name="type" th:value="${type}" type="hidden"/>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">选择教师：</label>
            <div class="col-sm-8">
                <select name="teacherId" class="form-control m-b" required>
                    <option value=""></option>
                    <option th:each="teacher : ${teacher}"  th:value="${teacher.teacherRecordId}" th:text="${teacher.teacherName}"></option>
                </select>
            </div>
        </div>

        <div class="form-group" th:if="${type == 1}">
            <label class="col-sm-3 control-label is-required">输入姓名：</label>
            <div class="col-sm-8">
                <input name="studentName" class="form-control"  type="text" required/>
            </div>
        </div>
        <div class="form-group" th:if="${type == 1}">
            <label class="col-sm-3 control-label is-required">输入学号：</label>
            <div class="col-sm-8">
                <input name="studentNumber" class="form-control"  type="text" required/>
            </div>
        </div>
        <div class="form-group" th:each="topic,topicStat : ${scoreTopic}">
            <div class="row">
                <label class="col-sm-3 control-label is-required">题目[[${topicStat.index + 1}]]：</label>
                <div class="col-sm-8">
                    <div class="form-control-static" th:text="${topic.topic}"></div>
                </div>
            </div>
            <div class="row">
                <label class="col-sm-3 control-label "></label>
                <div class="col-sm-8">
                    <input class="form-control" th:name="'ttt' +${topic.scoreTopicId}" type="number" min="1" max="10" placeholder="1-10" required/>
                </div>
            </div>
        </div>
    </form>
    <div class="row">
        <div class="col-sm-offset-5 col-sm-10">
            <button type="button" class="btn btn-sm btn-primary" onclick="submitHandler()"><i class="fa fa-check"></i>提  交
            </button>&nbsp;
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script>

    $("#form-topic-score").validate({
        focusCleanup: true
    });
    function submitHandler() {
        if ($.validate.form()) {
            var arrScore = [],indexScore = 0,sumScore=0;
            var data = $('#form-topic-score').serializeArray();
            data.forEach(function(item,index,arr){
                if(item.name.indexOf("ttt") == 0){
                    item.name = item.name.replace("ttt","");
                    arrScore[indexScore++] = item;
                    sumScore += Number(item.value);
                }
            });
            data.push({"name":"sumScore","value":sumScore});
            data.push({"name":"scoreTopic","value":JSON.stringify(arrScore)});
            $.operate.save("/tms/score/add", data);
        }
    }
</script>
</body>
</html>